package com.qf08;

import java.util.concurrent.*;

public class Demo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建线程池
        ExecutorService es = Executors.newFixedThreadPool(1);
        Future<Integer> future = es.submit(new Callable<Integer>() {

            @Override
            public Integer call() throws Exception {
                System.out.println(Thread.currentThread().getName() + "开始计算");
                int sum = 0;
                for (int i = 0; i <= 100; i++) {
                    sum += i;
                    Thread.sleep(100);
                }
                return sum;
            }
        });

        System.out.println(future.get());
        es.shutdown();
    }
}
